package com.sutuijingling.utils;

import android.graphics.Point;
import android.graphics.Rect;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

public class c {
    public static Object a = new Object();
    static Random b = new Random();
    static String c = "";
    static long d = 200;
    static String e = "/data/local/tmp";
    static String f = "/data/local/tmp/target.kt";
    static File g = new File(f);
    private static boolean h = true;
    private static boolean i = false;

    public static char a(char c) {
        return (c <= '@' || c >= '[') ? c : (char) (c + 32);
    }

    public static Point a(UiObject uiObject) throws UiObjectNotFoundException {
        Rect bounds = uiObject.getBounds();
        return new Point((bounds.left + bounds.right) / 2, (bounds.bottom + bounds.top) / 2);
    }

    public static UiObject a(String str) {
        System.out.println(" check res id:" + str);
        return new UiObject(new UiSelector().resourceId(str));
    }

    public static String a(String str, String str2) {
        if (org.apache.commons.lang.c.a(str) || org.apache.commons.lang.c.a(str2)) {
            return "";
        }
        int length = str.length();
        int length2 = str2.length();
        if (length < length2) {
            return "";
        }
        List arrayList = new ArrayList();
        StringBuilder stringBuilder = new StringBuilder();
        int i = 0;
        for (int i2 = 0; i2 < length2; i2++) {
            char a = a(str2.charAt(i2));
            for (int i3 = 0; i3 < length; i3++) {
                if (!arrayList.contains(Integer.valueOf(i3))) {
                    char a2 = a(str.charAt(i3));
                    if (a == ' ' || a == a2) {
                        i++;
                        arrayList.add(Integer.valueOf(i3));
                        stringBuilder.append(a);
                        break;
                    }
                }
            }
        }
        return stringBuilder.toString();
    }

    public static final void a() {
        System.out.println(" start to sleep 50ms");
        a(50);
        System.out.println(" start to sleep 50ms");
    }

    public static final void a(long j) {
        b(j);
    }

    public static void a(Point point) throws UiObjectNotFoundException {
        System.out.println(" center point :" + point);
        int nextInt = b.nextInt(2) + 1;
        Collection arrayList = new ArrayList();
        arrayList.add(c(" 0 2 0"));
        arrayList.add(c(" 0 0 0"));
        arrayList.add(c(" 1 330 1"));
        for (int i = 0; i < nextInt; i++) {
            a((List) arrayList, point.x, point.y);
        }
        arrayList.add(c(" 1 330 0"));
        arrayList.add(c(" 0 2 0"));
        arrayList.add(c(" 0 0 0"));
        a.a(org.apache.commons.lang.c.a(arrayList, '\n'), false);
    }

    public static void a(UiDevice uiDevice, int i, int i2) throws UiObjectNotFoundException {
        Point point = new Point(i, i2);
        if (h) {
            b(point);
        } else if (i) {
            a(point);
        } else {
            uiDevice.click(i, i2);
        }
    }

    public static void a(UiDevice uiDevice, int i, int i2, int i3, int i4, int i5) {
        a(uiDevice, new Point(i, i2), new Point(i3, i4), i5);
    }

    public static void a(UiDevice uiDevice, Point point, Point point2, int i) {
        if (h) {
            if (i > 20) {
                i = b.nextInt(10) + 20;
            }
            b(uiDevice, point, point2, i);
        } else if (i) {
            c(uiDevice, point, point2, i);
        } else {
            uiDevice.swipe(new Point[]{point, point2}, i);
        }
    }

    public static void a(UiDevice uiDevice, boolean z) {
        int displayHeight = uiDevice.getDisplayHeight();
        int displayWidth = uiDevice.getDisplayWidth();
        int nextInt = b.nextInt(displayWidth / 4) + 30;
        int nextInt2 = ((displayWidth / 4) + nextInt) + b.nextInt(displayWidth / 4);
        int nextInt3 = ((displayHeight * 7) / 8) - b.nextInt((displayHeight / 8) + 30);
        int nextInt4 = b.nextInt(10) + 10;
        Point point = new Point(nextInt, (displayHeight / 8) + b.nextInt((displayHeight / 8) + 10));
        Point point2 = new Point(nextInt2, nextInt3);
        Point point3 = z ? point2 : point;
        if (!z) {
            point = point2;
        }
        b(uiDevice, point3, point, nextInt4);
    }

    public static void a(UiDevice uiDevice, boolean z, int i) {
        a(uiDevice, z);
    }

    public static void a(UiDevice uiDevice, Point[] pointArr, int i) {
        int length = pointArr.length;
        Collection arrayList = new ArrayList();
        arrayList.add(c(" 0 2 0"));
        arrayList.add(c(" 0 0 0"));
        arrayList.add(c(" 1 330 1"));
        for (Point point : pointArr) {
            a((List) arrayList, point.x, point.y);
        }
        arrayList.add(c(" 1 330 0"));
        arrayList.add(c(" 0 2 0"));
        arrayList.add(c(" 0 0 0"));
        a.a(org.apache.commons.lang.c.a(arrayList, '\n'), false);
    }

    public static void a(UiObject uiObject, long j) throws UiObjectNotFoundException {
        Point e = e(uiObject);
        if (h) {
            b(e);
            f();
        } else if (i) {
            b(uiObject);
            f();
        } else {
            uiObject.clickAndWaitForNewWindow(j);
        }
    }

    private static void a(List list, int i, int i2) {
        list.add(c(" 3 48 " + (b.nextInt(5) + 14)));
        list.add(c(" 3 53 " + i));
        list.add(c(" 3 54 " + i2));
        list.add(c(" 3 57  0 "));
        list.add(c(" 0 2   0 "));
        list.add(c(" 0 0   0 "));
    }

    public static final void b() {
        System.out.println(" start to sleep 250ms");
        a(250);
        System.out.println(" start to sleep 250ms");
    }

    public static final void b(long j) {
        try {
            Thread.sleep(j);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void b(Point point) {
        d("tap " + point.x + " " + point.y + " " + 1 + " " + 200);
    }

    public static void b(UiDevice uiDevice, Point point, Point point2, int i) {
        if (i < 80) {
            i = uiDevice.getDisplayHeight() < 1200 ? b.nextInt(100) + 80 : b.nextInt(250) + 80;
        }
        int abs = Math.abs(point.x - point2.x);
        if (abs > 0 && abs <= r6) {
            i = (abs - (((b.nextInt(10) + 10) * abs) / 100)) - 1;
        }
        if (point.x == point2.x) {
            abs = Math.abs(point.y - point2.y);
            if (abs > 0 && abs <= r6) {
                i = (abs - (((b.nextInt(10) + 10) * abs) / 100)) - 1;
            }
        }
        d("drag " + point.x + " " + point.y + " " + point2.x + " " + point2.y + " " + i + " " + d);
    }

    public static void b(UiObject uiObject) throws UiObjectNotFoundException {
        if (uiObject.exists()) {
            a(a(uiObject));
        }
    }

    public static void b(java.lang.String r4) {
        /* JADX: method processing error */
/*
Error: java.util.NoSuchElementException
	at java.util.HashMap$HashIterator.nextNode(Unknown Source)
	at java.util.HashMap$KeyIterator.next(Unknown Source)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.applyRemove(BlockFinallyExtract.java:535)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.extractFinally(BlockFinallyExtract.java:175)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.processExceptionHandler(BlockFinallyExtract.java:79)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.visit(BlockFinallyExtract.java:51)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:31)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:37)
	at jadx.core.ProcessClass.processDependencies(ProcessClass.java:59)
	at jadx.core.ProcessClass.process(ProcessClass.java:42)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
*/
        /*
        r1 = 0;
        r0 = new java.io.File;	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r0.<init>(r4);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = r0.canExecute();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        if (r2 != 0) goto L_0x0010;	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
    L_0x000c:
        r2 = 1;	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r0.setExecutable(r2);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
    L_0x0010:
        r0 = java.lang.Runtime.getRuntime();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = "su";	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r1 = r0.exec(r2);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r0 = new java.io.DataOutputStream;	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = r1.getOutputStream();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r0.<init>(r2);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = new java.lang.StringBuilder;	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2.<init>();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r3 = "/system/bin/sh  ";	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = r2.append(r3);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = r2.append(r4);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r3 = " \n";	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = r2.append(r3);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = r2.toString();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r0.writeBytes(r2);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r2 = "exit\n";	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r0.writeBytes(r2);	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r0.flush();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        r1.waitFor();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        if (r1 == 0) goto L_0x004f;
    L_0x004c:
        r1.destroy();
    L_0x004f:
        return;
    L_0x0050:
        r0 = move-exception;
        r0.printStackTrace();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        if (r1 == 0) goto L_0x004f;
    L_0x0056:
        r1.destroy();
        goto L_0x004f;
    L_0x005a:
        r0 = move-exception;
        r0.printStackTrace();	 Catch:{ IOException -> 0x0050, InterruptedException -> 0x005a, all -> 0x0064 }
        if (r1 == 0) goto L_0x004f;
    L_0x0060:
        r1.destroy();
        goto L_0x004f;
    L_0x0064:
        r0 = move-exception;
        if (r1 == 0) goto L_0x006a;
    L_0x0067:
        r1.destroy();
    L_0x006a:
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.sutuijingling.utils.c.b(java.lang.String):void");
    }

    private static String c(String str) {
        return String.format(" %s %s %s", new Object[]{"sendevent", h(), str});
    }

    public static final void c() {
        b.b(" start to sleep 1s", new Object[0]);
        a(1000);
        b.b(" over to sleep 1s", new Object[0]);
    }

    private static void c(UiDevice uiDevice, Point point, Point point2, int i) {
        List arrayList = new ArrayList();
        arrayList.add(c(" 0 2 0"));
        arrayList.add(c(" 0 0 0"));
        arrayList.add(c(" 1 330 1"));
        int i2 = point2.x - point.x;
        if (i2 <= 0) {
            i2 = -i2;
        }
        double d = ((double) i2) / ((double) (i * i));
        i2 = point2.y - point.y;
        if (i2 <= 0) {
            i2 = -i2;
        }
        double d2 = ((double) i2) / ((double) (i * i));
        Point[] pointArr = new Point[i];
        Object obj = point2.x > point.x ? 1 : null;
        Object obj2 = point2.y > point.y ? 1 : null;
        int i3 = point.x;
        int i4 = point.y;
        int i5 = i3;
        i3 = 1;
        while (i3 <= i) {
            pointArr[i3 - 1] = new Point(i5, i4);
            i5 = obj != null ? (i5 + 1) + ((int) Math.round(2.0d * d)) : (i5 - 1) - ((int) Math.round(2.0d * d));
            i3++;
            i4 = obj2 != null ? (i4 + 1) + ((int) Math.round(2.0d * d2)) : (i4 - 1) - ((int) Math.round(2.0d * d2));
        }
        a(uiDevice, pointArr, i);
    }

    public static void c(UiObject uiObject) throws UiObjectNotFoundException {
        Point e = e(uiObject);
        if (h) {
            b(e);
        } else if (i) {
            b(uiObject);
        } else {
            uiObject.click();
        }
    }

    public static final void d() {
        System.out.println(" start to sleep 2s");
        a(2000);
        System.out.println(" over to sleep 2s");
    }

    public static void d(UiObject uiObject) throws UiObjectNotFoundException {
        Point e = e(uiObject);
        if (h) {
            b(e);
            f();
        } else if (i) {
            b(uiObject);
            f();
        } else {
            uiObject.clickAndWaitForNewWindow();
        }
    }

    private static void d(String str) {
        b.b(" target cmd :" + str, new Object[0]);
        try {
            a.b(" rm -r " + f);
            a.a(f, str);
            a.b(" chmod 777 " + f);
            a.b("/data/local/tmp/ktouch " + h() + " " + f);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static Point e(UiObject uiObject) throws UiObjectNotFoundException {
        Rect bounds = uiObject.getBounds();
        int centerX = uiObject.getBounds().centerX();
        return new Point((centerX - (bounds.width() / 8)) + b.nextInt(bounds.width() / 4), b.nextInt(bounds.height() / 4) + (uiObject.getBounds().centerY() - (bounds.height() / 8)));
    }

    public static final void e() {
        System.out.println(" start to sleep 3s");
        a(3000);
        System.out.println(" over to sleep 3s");
    }

    public static final void f() {
        System.out.println(" start to sleep 5s");
        a(5000);
        System.out.println(" over to sleep 5s");
    }

    public static final void g() {
        System.out.println(" start to sleep 7s");
        a(7000);
        System.out.println(" over to sleep 7s");
    }

    public static String h() {
        return i();
    }

    public static String i() {
        try {
            if (!org.apache.commons.lang.c.a(c) && c.startsWith("/dev/input/event")) {
                return c;
            }
            String str = "/data/data/jp.jun_nama.test.utf7ime/files/input.txt";
            if (!new File(str).exists()) {
                return "/dev/input/event3";
            }
            str = a.a(str);
            if (org.apache.commons.lang.c.a(str) || !str.startsWith("/dev/input/event")) {
                return "/dev/input/event3";
            }
            if (!str.startsWith("/dev/input/event")) {
                return str;
            }
            c = str;
            return str;
        } catch (Exception e) {
            e.printStackTrace();
            return "/dev/input/event3";
        }
    }
}
